登录 白背景

274. H 指数

https://leetcode.cn/problems/h-index/description

  • 难度:中等
  • 提交时间:2023.10.30 18:38
  • 0ms 击败 100.00%使用 Go 的用户
  • 2.08MB 击败 22.22%使用 Go 的用户

func hIndex(citations []int) int {
    sort.Ints(citations)
    n := len(citations)
    maxH := 0
    for i, item := range citations {
        if item == 0 {
            continue
        }
        if item < n-i {
            continue
        }
        m := min(item, n-i)
        if m < maxH {
            break
        }
        maxH = max(m, maxH)
    }
    return maxH
}

func max(x, y int) int {
    if x > y {
        return x
    }
    return y
}

func min(x, y int) int {
    if x < y {
        return x
    }
    return y
}